home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
dos
/
c
/
tagsgen.exe
/
WD.CB
< prev
next >
Wrap
Text File
|
1991-09-30
|
6KB
|
175 lines
/*======================================================================*/
/* where-defined Leonid Kokin 9/26/1991 */
/* */
/* Use: position cursor on a symbol and press <ctrl-w> */
/* */
/* Comment: in order to have this macro loaded automatically when */
/* Brief is entered, add the -mwd switch in your autoexec.bat */
/* and place your wd.cm in the c:\brief\macros directory. */
/* */
/* DEFAULT_TAG_FILE = default name of the tag file being used. This is */
/* the name of the tag file that will come up first */
/* upon pressing <ctrl-w>. If, for example your tag */
/* file is xyz.tag, then you shoud #define it to be */
/* xyz below. */
/* */
/* PATH_ENV_VAR = name of the environment variable containing the */
/* path to your source files. This will enable you */
/* to run this macro from any directory. */
/* Example: if your source files are in C:\SOURCES */
/* you must set an environment variable, say SRC, */
/* with SET SRC=C:\SOURCES in your autoexec.bat file */
/* then #define PATH_ENV_VAR to be SRC. */
/* */
/* ALLOWABLES = set of allowable characters. This macro highlights*/
/* a token comprizing only of allowable characters. */
/* These have been preset for you to include the */
/* underscore (_), lower case letters (a-z), upper */
/* case letters (A-Z), and integers (0-9). You may */
/* want to add other characters to this list, such */
/* ?, $, etc. */
/*======================================================================*/
/* */
/* Modify the variables below and the recompile with <alt-F10>. */
/* */
#define DEFAULT_TAG_FILE "???"
#define PATH_ENV_VAR "???"
#define ALLOWABLES "_a-zA-Z0-9"
/*======================================================================*/
void goback();
void goto_next_occurence();
string prev_word();
string grab_word();
int tag_buffer, curr_buff, row0, col0;
string symbol0, prod;
wd() /* assign keys */
{
assign_to_key("<Ctrl-w>", "where_defined");
assign_to_key("<Ctrl-v>", "nothing");
assign_to_key("<Ctrl-r>", "nothing");
}
where_defined() /* call this macro when <ctrl-w> is pressed */
{
string symbol, tag_file, line, line_no, file_name;
int tag_file_buffer, col, n = 0;
pause_on_error(1);
inq_position(row0, col0);
if(first_time()) prod = DEFAULT_TAG_FILE;
if(get_parm(NULL, symbol0, "Enter symbol: ", NULL, grab_word()))
if(get_parm(NULL, prod, "Enter product: ", NULL, prod))
if(exist(tag_file=inq_environment(PATH_ENV_VAR)+prod+".TAG"))
{
raise_anchor();
symbol = symbol0 + " ";
curr_buff = set_buffer(tag_file_buffer = create_buffer("tagfile", tag_file));
tag_buffer = create_buffer("tag2", NULL);
top_of_buffer();
while(search_fwd(symbol, 0))
{
inq_position(NULL, col);
if(col == 1)
{
n++;
line = read();
down();
set_buffer(tag_buffer);
insert(line);
set_buffer(tag_file_buffer);
}
else down();
}
set_buffer(tag_buffer);
top_of_buffer();
save_position();
set_buffer(curr_buff);
delete_buffer(tag_file_buffer);
switch (n)
{
case 0: message("0 occurences found");
case 1:
{
assign_to_key("<Ctrl-r>", "goback");
assign_to_key("<Ctrl-v>", "goto_next_occurence");
goto_next_occurence();
}
default:
{
beep();
message("%d occurences, <ctrl-v>:view, <ctrl-r>:return", n);
if(n != 0)
{
assign_to_key("<Ctrl-v>", "goto_next_occurence");
assign_to_key("<Ctrl-r>", "goback");
}
}
}
}
else message("error: %s file does not exist", tag_file);
raise_anchor();
}
string grab_word()
{
int col1, col2;
if(search_string("[" + ALLOWABLES + "]", read(1)))
{
search_fwd("[~" + ALLOWABLES + "]");
left();
inq_position(NULL, col2);
drop_anchor(1);
search_back("[~" + ALLOWABLES + "]");
search_fwd("[" + ALLOWABLES + "]");
inq_position(NULL, col1);
return(read(col2 - col1 + 1));
}
else return("");
}
string prev_word()
{
string str = "<|[ \\t][~ \\t]+[ \\t\\n]";
return(trim(ltrim(read(search_back(str, 2) - 1))));
}
void goto_next_occurence()
{
int n1, n2, t1, t2, file_buff, line_no1, line_no2;
string file_name;
set_buffer(tag_buffer);
restore_position();
search_fwd("[ ]\\c[~ ]");
n1 = index(read(), "(");
n2 = index(read(), ")");
file_name = substr(read(), 1, n1 - 1);
line_no1 = atoi(substr(read(), n1 + 1, n2 - n1 - 1));
beginning_of_line();
down();
if(trim(ltrim(read())) == "") top_of_buffer();
save_position();
edit_file(file_name);
goto_line(line_no1);
search_back("[<;][~\\n]@" + symbol0 + "[ \\t\\n]", 2, 0);
inq_position(line_no2);
if((line_no1-line_no2) > 20) goto_line(line_no1);
to_top();
display_file_name();
}
void goback()
{
set_buffer(curr_buff);
attach_buffer(curr_buff);
move_abs(row0, col0);
display_file_name();
}